package cn.edu.Controller;

import cn.edu.DAO.AdminDAOByXML;
import cn.edu.DAO.OrderDAOByXML;
import cn.edu.DAO.UserDAOByXML;
import cn.edu.DAO.travelshopByXML;
import cn.edu.DO.AdminDO;
import cn.edu.DO.OrderDO;
import cn.edu.DO.TravelShopDO;
import cn.edu.DO.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class adminController {
    @Autowired
    UserDAOByXML userDAO;
    @Autowired
    AdminDAOByXML adminDAO;
    @Autowired
    OrderDAOByXML orderDAO;
    @Autowired
    travelshopByXML travelshopDAO;
    @RequestMapping("/admin")
    public String adminLogin(){
        return "admin/adminLogin";
    }
    @RequestMapping("/adminCheck")
    public String loginCheck1(AdminDO user, Map map, HttpSession session){
        if(adminDAO.queryAdminToLogin(user.getId(),user.getPassword())!=null){

            session.setAttribute("id",user.getId());
            session.setAttribute("password",user.getPassword());
            map.put("username",session.getAttribute("username"));
            return "admin/AdminIndex";
        }
        else{
            map.put("error","用户名或密码错误");
        }
        return "admin/adminLogin";
    }
    @RequestMapping("/getUserDetail")
    public String getUserDetail(Map map){
        List<OrderDO> ords = new ArrayList<>();
        ords = orderDAO.SelectAll();
        map.put("list",ords);
        return "admin/GetUserDetail";
    }
    @RequestMapping("/SelectOrder")
    public String SelectOrder(HttpServletRequest request,HttpSession session){
        String id = request.getParameter("id");
        OrderDO order = new OrderDO();
        order = orderDAO.selectById(id);
        session.setAttribute("order",order);
        return "admin/SelectOrder";

    }
    @RequestMapping("/addTravel")
    public String addTravel(){
        return "admin/AddTravelShop";
    }

    @RequestMapping("/TravelShopAdd")
    public String TravelShopAdd(HttpServletRequest request){
        TravelShopDO travel = new TravelShopDO();
        travel.setSid(request.getParameter("sid"));
        travel.setRoute(request.getParameter("route"));
        travel.setProject(request.getParameter("project"));
        travel.setTitle(request.getParameter("title"));
        travel.setPrice(request.getParameter("price"));
        travel.setStatus(request.getParameter("status"));
        travel.setImage(request.getParameter("image"));
        travel.setIntroduction(request.getParameter("introduction"));
        travelshopDAO.insertShop(travel);
        return "admin/AddTravelSuccess";
    }

}
